from utils.compat import debug

def debug_wrap(func):
    def decorated(*args, **kwargs):
        debug("Calling function %s with arguments:"  % func.__name__)
        for num, arg in enumerate(args):
            debug("  %s: %s (type: %s)" % (num, arg, type(arg)))
        for key, arg in kwargs.iteritems():
            debug("  %s: %s (type: %s)" % (key, arg, type(arg)))
        return_value = func(*args, **kwargs)
        debug("Function (%s) returned: %s (type: %s)" %
              (func.__name__, return_value, type(return_value)))
        return return_value
    return decorated